<?php


namespace app\index\controller;


use app\index\model\User;
use think\Exception;
use think\facade\Log;
use think\Request;

class Order
{
    protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    public function orderList()
    {
        $userList = User::where('limit', 0)->field('username, role')->limit(10)->select();
        return json($userList);
    }

    public function orderSave()
    {

        if (!$this->request->isAjax()) {
            if ($this->request->isPost()) {
                $param = $this->request->param();
                try {
                    $result = User::create($param);
                } catch (Exception $e) {
                    Log::error('错误日志记录' . $e);
                }
                if ($result) {
                    return json('success', 200);
                }
                return json('error, 系统异常', 500);
            }

            return json('error, 请求方式错误2', 500);
        }
        return json('error, 请求方式错误1', 500);
    }
}